#ifndef TREEDOC_H
#define TREEDOC_H

#include <QTreeWidget>
#include "userlist.h"
#include "DbConnection.h"
#include "docentity.h"
class TreeDoc : public QTreeWidget
{
    Q_OBJECT
public:
    enum FilterType {Scope,State};
    explicit TreeDoc(DbConnection* db, QWidget *parent = 0);
    bool  initialization();
    UserList* users();
    DbConnection::QueryResult execute(const QString&sql);
    void setCommonNumbering(const bool&commonNumbering);
    DbConnection* db();
    QList<QAction*> filter(const FilterType&filterType);
    QString statusByState(const int&state);
    bool highlight() const;
    void setHighlight(const bool&on);
    bool isWasChangedItems() const;
private:
    UserList m_users;
    DbConnection* m_db;
    bool m_commonNumbering;
    QString m_macActionTypeFilter;
    QString m_macActionStateFilter;
    QMap<int,QString> m_statuses;
    QMap<int,QString> m_colors;
    bool m_highlight;
    QList<DocEntity*> m_changedItems;
    void setItemsVisible(DocEntity* item,const QString&filterName);
    void setMacActionStateFilter(const QString&filterName);
    QColor colorFromString(const QString&color);
protected:
    void contextMenuEvent(QContextMenuEvent* event);
signals:
    void childWakeUp(DocEntity* item);
    void state_message(const QString&mess,int alignment, const QColor&color);
    void state_message(const QString&mess, int timeout);
    void itemWasChanged();
    void filterWasChange();
    void wasRefreshItem();
public slots:
    void removeItem(DocEntity* item);
    void appendMacAction(const bool&inner);
    void turnOnHighlight(DocEntity* item);
    void turnOffHighlight(DocEntity* item);
    void itemByFID(const QString&FID);
    void refresh();
    void onSavedItem(DocEntity*item);
    void onChangedItem(DocEntity* item);
private slots:
    void onNodeWakeUp(QTreeWidgetItem* item);
    void setMacActionTypeFilter();
    void setMacActionStateFilter();
    void onItemRefresh(DocEntity* item);
};

#endif // TREEDOC_H
